package com.topnav.mc.admin.controller;

import com.js.lib.annotation.ApiLogger;
import com.js.lib.result.Result;
import com.topnav.mc.admin.entity.Permission;
import com.topnav.mc.admin.service.IPermissionService;
import com.topnav.mc.base.CurdController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "admin/permission", tags = "权限数据")
@RestController
@CrossOrigin
@RequestMapping("admin/permission")
public class PermissionController extends CurdController<Permission, IPermissionService> {
    @Autowired
    private IPermissionService permissionService;

    /**
     * 查询所有权限
     */
    @ApiLogger(apiName="/query/all")
    @ApiOperation(value = "所有权限")
    @GetMapping("/query/all")
    @ResponseBody
    public Result allPermission() {
        List<Permission> data= permissionService.findAllPermission();
        return Result.ok(data);
    }


    /**
     * 查询用户权限
     */
    @ApiLogger(apiName="/query/by/user/{userId}")
    @ApiOperation(value = "查询用户权限")
    @GetMapping("/query/by/user/{userId}")
    @ResponseBody
    public Result byUser(@PathVariable Long userId) {
        List<Permission> data= permissionService.findPermissionByUserId(userId);
        return Result.ok(data);
    }
}
